package com.bs.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bs.entity.Acceptability;
import com.bs.entity.ClockInfo;
import com.bs.service.AcceptabilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/Acceptability")
public class AcceptabilityCon {
    @Autowired
    AcceptabilityService acceptabilityService;

    // 更新考勤合格率
    @GetMapping("/updateById")
    public void updateAcceptability(Integer id){
        List<HashMap<String, String>> listByMonth = acceptabilityService.getListByMonth(id);

    }


    @GetMapping("/getById")
    public Object[] getListByMonth(Integer id){
        List<HashMap<String, String>> listByMonth = acceptabilityService.getListByMonth(id);
        return listByMonth.toArray();
    }


    @GetMapping("/Page")
    public IPage<Acceptability> acceptabilityPage(@RequestParam Integer pageNum
            , @RequestParam Integer pageSize
            , @RequestParam(required = false) Integer id){
        IPage<Acceptability> page = new Page<>(pageNum,pageSize);
        QueryWrapper<Acceptability> queryWrapper = new QueryWrapper<>();
        if(Objects.nonNull(id)){
            queryWrapper.lambda().eq(Acceptability::getId,id);
        }
        return acceptabilityService.page(page, queryWrapper);
    }
}
